package com.penglecode.netty.client;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NettyClientHandler extends SimpleChannelHandler {

	private static final Logger logger = LoggerFactory.getLogger(NettyClientHandler.class);
	
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
		logger.info("[client] received message from server, message = {}", e.getMessage());
		e.getChannel().setAttachment(e.getMessage());
	}

	public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
		logger.info("[client] a client channel connected to server!");
	}

}
